package com.hopu.v1.controller.admin.exam;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.v1.pojo.common.Delete;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.common.Save;
import com.hopu.v1.pojo.common.Update;
import com.hopu.v1.pojo.exam.ExamGrades;
import com.hopu.v1.service.admin.exam.ExamGradesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: ExamGradesController
 * Description:
 *
 * @Author lh
 * @Create 2024/9/29 15:34
 * @Version 1.0
 */
@RestController
@RequestMapping("/examGrades")
public class ExamGradesController {
    @Autowired
    private ExamGradesService examGradesService;

    /**
     * 新增
     * @param examGrades
     * @return
     */
    @PostMapping("/add")
    public R add(@Validated(Save.class) @RequestBody ExamGrades examGrades) {
        System.out.println(examGrades);
        examGradesService.add(examGrades);
        return R.ok("添加成功");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("/del")
    public R del(@Validated(Delete.class) Integer id) {
        System.out.println(id);
        examGradesService.del(id);
        return R.ok("操作成功");
    }

    /**
     * 修改
     * @param examGrades
     * @return
     */
    @PostMapping("/update")
    public R update(@Validated(Update.class) @RequestBody ExamGrades examGrades) {
        examGradesService.update(examGrades);
        return R.ok("操作成功");
    }


    @GetMapping("/selectList")
    public R selectList(Page<ExamGrades> page, ExamGrades examGrades, String endTime) {
        System.out.println(examGrades);
        System.out.println(endTime);
        return R.ok(examGradesService.selectList(page, examGrades,endTime));
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @PostMapping("/batchDel")
    public R batchDel(ArrayList<Integer> ids) {
        System.out.println(ids);
        examGradesService.batchDel(ids);
        return R.ok("操作成功");
    }

    /**
     * 批量新增
     * @param examGradesList
     * @return
     */
    @PostMapping("/batchAdd")
    public R batchAdd(@RequestBody List<ExamGrades> examGradesList) {
        System.out.println(examGradesList);
        examGradesService.batchAdd(examGradesList);
        return R.ok("添加成功");
    }

    /**
     * 根据考试记录Id和题目Id查询学生答案
     * @param examRecordId questionId
     * @return
     */
    @GetMapping("/studentIdGrades")
    public R selectGrades(Integer examRecordId,String classId) {
      return R.ok(examGradesService.selectGrades(examRecordId,classId));
    }

    /**
     * 批改成绩
     * @param examGradesList
     * @return
     */
    @PostMapping("/gradeCorrection")
    public R gradeCorrection(@RequestBody List<ExamGrades> examGradesList){
        examGradesService.gradeCorrection(examGradesList);
        return R.ok("操作成功");
    }
}
